<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
      xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
      layout:decorator="layout/tpl">
<head>
    <meta charset="UTF-8"/>
    <title>添加用户</title>
    <style>
        form {
            padding: 10px;
        }
    </style>
</head>
<body layout:fragment="content">
<form class="layui-form  layui-form-pane">

    <div class="layui-form-item">
        <label class="layui-form-label">企业编号</label>
        <div class="layui-input-block">
            <input type="text" id="qid" name="qid" lay-verify="required" autocomplete="off" placeholder="请输入企业编号" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">商品名称</label>
        <div class="layui-input-block">
            <input type="text" id="spmc" name="spmc" lay-verify="required" autocomplete="off" placeholder="请输入商品名称" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">规格型号</label>
        <div class="layui-input-block">
            <input type="text" id="ggxh" name="ggxh" autocomplete="off" lay-verify="required" placeholder="请输入规格型号" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">单价</label>
        <div class="layui-input-block">
            <input type="text" id="price" name="price" autocomplete="off" lay-verify="required" placeholder="请输入单价" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">库存</label>
        <div class="layui-input-block">
            <input type="text" id="stock" name="stock" autocomplete="off" lay-verify="required" placeholder="请输入库存数" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">税收编码</label>
        <div class="layui-input-block">
            <input type="text" id="spbm" name="spbm" autocomplete="off" placeholder="请输入税收编码" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item" pane="">
        <label class="layui-form-label">是否可用</label>
        <div class="layui-input-block">
            <input type="checkbox" id="available" checked="" name="available" lay-skin="switch" lay-filter="available" lay-text="ON|OFF">
        </div>
    </div>

    <button hidden id="sb" lay-submit="" lay-filter="sb"></button>
</form>
</body>
<script type="text/javascript" layout:fragment="myscript">
    var available = true;
    layui.use('form', function(){
        form = layui.form;
        form.on('switch(available)' , function(data){
            available = data.elem.checked;
        });
        form.on('submit(sb)', function(data){
            $.post("add" , data.field , function(ret){
                if (ret.code == 0) {
                    parent.layer.close(parent.sIndex);
                    parent.productGrid.reload({
                        page: {
                            curr: 1 //重新从第 1 页开始
                        }
                    });
                }
            } , "json");
            return false;
        });
    });
</script>
</html>